package pm.oo;

import java.awt.*;

/**
 * Class to pass the system window handle to the OpenOffice.org toolkit.
 * It use special JNI methods to get the system handle of used java window.
 * <p/>
 * Attention!
 * Use JNI functions on already visible canvas objects only!
 * Otherwise they can make some trouble.
 *
 * @author Andreas Schl&uuml;ns
 * @created 22.02.2002 08:47
 */

public class NativeOOViewComponent extends java.awt.Canvas {
	/**
	 * constructor
	 * Does nothing realy.
	 * We can use our JNI mechanism for an already visible
	 * canvas only. So we overload the method for showing ("setVisible()")
	 * and make our intialization there. BUt we try to show an empty clean
	 * window till there.
	 */
	public NativeOOViewComponent() {
		this.setBackground(Color.white);
	}


	/**
	 * JNI interface of this class
	 * These two methods are implemented by using JNI mechanismen.
	 * The will be used to get the platform dependent window handle
	 * of a java awt canvas. This handle can be used to create an office
	 * window as direct child of it. So it's possible to plug Office
	 * windows in a java UI container.
	 * <p/>
	 * Note:
	 * Native code for windows register special function pointer to handle
	 * window messages ... But if it doesn't check for an already registered
	 * instance of this handler it will do it twice and produce a stack overflow
	 * because such method call herself in a never ending loop ...
	 * So we try to use the JNI code one times only and safe already getted
	 * informations inside this class.
     * @return fuck
     */
	public native int getNativeWindowSystemType();

	private native long getNativeWindow(); // private! => use getHWND() with cache mechanism!

	public Integer getHWND() {
        return (int) getNativeWindow();
	}
}
